package com.petAdoption.manager.controller;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.petAdoption.manager.entity.Examinedeliver;
import com.petAdoption.manager.entity.Pet;
import com.petAdoption.manager.service.IExaminedeliverService;
import com.petAdoption.manager.service.IExamineneckService;
import com.petAdoption.manager.service.IPetService;
import com.petAdoption.manager.util.Result;
import com.petAdoption.manager.vo.ExaminedeliverVO;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 王倩茹
 * @since 2023-08-28
 */
@RestController
@RequestMapping("/examinedeliver")
public class ExaminedeliverController {
    @Resource
    private IExaminedeliverService examinedeliverService;
    @Resource
    private IPetService petService;
    @Resource
    private Result result;


    @GetMapping("/findAll")
    public Result findAll(){
        List<ExaminedeliverVO> list = examinedeliverService.findAll();
        if(list!=null && !list.isEmpty()){
            return result.success("宠物审核表查找成功",list);
        }
        return result.fail("查找失败");
    }

    @PutMapping("/updateDeliver")
    public Result updateDeliver(@RequestBody Examinedeliver examinedeliver){
        int i=0;
        if (examinedeliver.getExaminedeliverStatus()==1){
            i = examinedeliverService.updateStatus(examinedeliver);
            petService.update(new UpdateWrapper<Pet>().set("pet_status",1).eq("pet_id",examinedeliver.getExaminedeliverPet()));
        }else if (examinedeliver.getExaminedeliverStatus()==2){
           i =  examinedeliverService.updateStatus(examinedeliver);
            petService.update(new UpdateWrapper<Pet>().set("pet_delete",1).eq("pet_id",examinedeliver.getExaminedeliverPet()));

        }
        if(i>0){
            return result.success("修改成功");
        }else {
            return result.fail("修改失败");
        }
    }

    @GetMapping("/findByStatus/{examinedeliverStatus}")
    public Result findByStatus(@PathVariable Integer examinedeliverStatus){
        List<ExaminedeliverVO> list = examinedeliverService.findByStatus(examinedeliverStatus);
        if(list!=null && !list.isEmpty()){
            return result.success("查找成功",list);
        }
        return result.fail("查找失败");
    }
}
